home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / Particle S210796122001.psc / Cylinder.cls < prev    next >
Encoding:
Visual Basic class definition  |  2001-06-12  |  4.9 KB  |  193 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "Cylinder"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
  15. Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
  16. Option Explicit
  17. Const CurrentModule As String = "Cylinder"
  18. Private mvarMaxDist As Long
  19. Private Parts() As Particle
  20.  
  21. Public Sub RandomCylinder(XL As Long, YL As Long, _
  22.         ZL As Long, Optional Num As Long = 50, _
  23.         Optional MaxDist As Long = 5, Optional _
  24.         Speed As Double = 0.1)
  25.     On Error GoTo Err_Init
  26.     Dim i As Long
  27.     mvarMaxDist = MaxDist
  28.     ReDim Parts(Num)
  29.     For i = 1 To Num
  30.         Set Parts(i) = New Particle
  31.         With Parts(i)
  32.             .YLoc = YL
  33.             .ZLoc = ZL
  34.             .XLoc = XL - MaxDist + (Rnd * 2 * MaxDist)
  35.             .ZLoc = ZL - MaxDist + (Rnd * 2 * MaxDist)
  36.             .YVel = -(Rnd * 0.4) - Speed
  37.             .PartType = 1
  38.             .SizeType = 3
  39.             .MaxSize = 2
  40.             .Life = -(100 / Num) * i
  41.             .LifeSpan = 2000
  42.         End With
  43.     Next
  44.     Exit Sub
  45.  
  46. Err_Init:
  47.     HandleError CurrentModule, "RandomCylinder", Err.Number, Err.Description
  48. End Sub
  49.  
  50. Public Function MoveParticles() As Boolean
  51.     On Error GoTo Err_Init
  52.     Dim SomeLeft As Boolean
  53.     Dim i As Long
  54.     SomeLeft = False
  55.     For i = 1 To UBound(Parts)
  56.         Parts(i).XVel = mvarMaxDist * Cos(Parts(i).Life / 10) '+ (Int(Rnd * 3) - 1)
  57.         Parts(i).MoveParticle
  58.         If Parts(i).ParticleDead = False Then
  59.             SomeLeft = True
  60.         End If
  61.     Next
  62.     MoveParticles = SomeLeft
  63.     Exit Function
  64.  
  65. Err_Init:
  66.     HandleError CurrentModule, "MoveParticles", Err.Number, Err.Description
  67. End Function
  68.  
  69. Public Sub MoveParticles3D()
  70.     On Error GoTo Err_Init
  71.     Dim i As Long
  72.     For i = 1 To UBound(Parts)
  73.         Parts(i).XVel = mvarMaxDist * Cos(Parts(i).Life / 10) '+ (Int(Rnd * 3) - 1)
  74.         Parts(i).YVel = mvarMaxDist * Cos(Parts(i).Life / 10) '+ (Int(Rnd * 3) - 1)
  75.         Parts(i).MoveParticle
  76.     Next
  77.     Exit Sub
  78.  
  79. Err_Init:
  80.     HandleError CurrentModule, "MoveParticles3D", Err.Number, Err.Description
  81. End Sub
  82.  
  83. Public Sub DrawParticles()
  84.     On Error GoTo Err_Init
  85.     Dim i As Long
  86.     For i = 1 To UBound(Parts)
  87.         Parts(i).DrawParticle
  88.     Next
  89.     Exit Sub
  90.  
  91. Err_Init:
  92.     HandleError CurrentModule, "DrawParticles", Err.Number, Err.Description
  93. End Sub
  94.  
  95. Public Sub DrawParticles3D(hDC As Long)
  96.     On Error GoTo Err_Init
  97.     Dim i As Long
  98.     For i = 1 To UBound(Parts)
  99.         Parts(i).DrawParticle3D hDC
  100.     Next
  101.     Exit Sub
  102.  
  103. Err_Init:
  104.     HandleError CurrentModule, "DrawParticles3D", Err.Number, Err.Description
  105. End Sub
  106.  
  107. Public Sub RemoveColor(Num As Long)
  108.     On Error GoTo Err_Init
  109.     Dim i As Long
  110.     For i = Num To UBound(Parts)
  111.         With Parts(i)
  112.             .RemoveColor Num
  113.         End With
  114.     Next
  115.     Exit Sub
  116.  
  117. Err_Init:
  118.     HandleError CurrentModule, "RemoveColor", Err.Number, Err.Description
  119. End Sub
  120.  
  121. Public Sub RemoveLastColor()
  122.     On Error GoTo Err_Init
  123.     Dim i As Long
  124.     For i = 1 To UBound(Parts)
  125.         With Parts(i)
  126.             .RemoveLastColor
  127.         End With
  128.     Next
  129.     Exit Sub
  130.  
  131. Err_Init:
  132.     HandleError CurrentModule, "RemoveLastColor", Err.Number, Err.Description
  133. End Sub
  134.  
  135. Public Sub AddColor(Red As Long, Green As Long, Blue As Long)
  136.     On Error GoTo Err_Init
  137.     Dim i As Long
  138.     For i = 1 To UBound(Parts)
  139.         With Parts(i)
  140.             .AddColor Red, Green, Blue
  141.         End With
  142.     Next
  143.     Exit Sub
  144.  
  145. Err_Init:
  146.     HandleError CurrentModule, "AddColor", Err.Number, Err.Description
  147. End Sub
  148.  
  149. Public Sub MoveAll(x As Long, Y As Long, Z As Long)
  150.     On Error GoTo Err_Init
  151.     Dim i As Long
  152.     For i = 1 To UBound(Parts)
  153.         With Parts(i)
  154.             .XLoc = .XLoc + x
  155.             .YLoc = .YLoc + Y
  156.             .ZLoc = .ZLoc + Z
  157.         End With
  158.     Next
  159.     Exit Sub
  160.  
  161. Err_Init:
  162.     HandleError CurrentModule, "MoveAll", Err.Number, Err.Description
  163. End Sub
  164.  
  165. Public Sub Render(pic As PictureBox)
  166.     On Error GoTo Err_Init
  167.     Dim NextTime As Long
  168.     Do
  169.         'Check for user stop
  170.         DoEvents
  171.         If QuitRender = True Then
  172.             Exit Do
  173.         End If
  174.         'Wait the minimum amount of time
  175.         If timeGetTime < NextTime Then
  176.             DoEvents
  177.         Else
  178.             'Draw the remaining live particles
  179.             pic.Cls
  180.             NextTime = timeGetTime + Speed
  181.             If MoveParticles = True Then
  182.                 DrawParticles
  183.             Else
  184.                 Exit Do
  185.             End If
  186.         End If
  187.     Loop
  188.     Exit Sub
  189.  
  190. Err_Init:
  191.     HandleError CurrentModule, "Render", Err.Number, Err.Description
  192. End Sub
  193.